package com.example.securitydemos.config;

import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * @author linjy on 2023/1/9
 */
//@EnableWebSecurity
public class SecurityConfig_HTTP基本认证 extends WebSecurityConfigurerAdapter {

    /**
     * 这段代码中httpBasic()方法，就是用来开启基本认证的，其实默认采用的就是基本认证！
     */
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        //1.配置基本认证方式
        http.authorizeRequests()
                //对任意请求都进行认证
                .anyRequest()
                .authenticated()
                .and()
                //开启basic认证
                .httpBasic();
    }

}

